use std::fs;
use regex::Regex;
use fltk::{prelude::*, *};
mod myuifile;

fn main() {
    let app = app::App::default();
    let mut ui = myuifile::UserInterface::make_window();
    //let win = ui.my_win.clone();

    ui.lb_ver.set_value("版本:");

    let mut vers: Vec<String> = Vec::new();
    for p in fs::read_dir("/home/manager/prj/ZJ").unwrap() {
        let path = String::from(format!("{}", p.unwrap().path().display()));
        //let path = String::from(p.unwrap().path().display());
        let pos = path.rfind("/").unwrap();
        let (_, dir) = path.split_at(pos + 1);
        println!("{}", path);
        println!("{}", dir);

        let r = Regex::new(r"bin_(.+)").unwrap();
        let ver = match r.captures(dir) {
            None => continue,
            Some(cap) => format!("{}", &cap[1]),
        };
        println!("{}", ver);
        vers.push(ver);
    }
    ui.cb_ver.add_choice(&vers.join("|"));
    ui.cb_ver.set_value(0);

    ui.btn_switch.set_callback(move |_| {
        println!("{}", ui.cb_ver.choice().unwrap());
        println!("Works!");
    });

    app.run().unwrap();
}

